home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 426-450 / disk_447 / sman / cp / mandcp.asm < prev    next >
Assembly Source File  |  1992-05-06  |  5KB  |  234 lines

  1. * SManCP
  2. * By David M. McKinstry.
  3. * This version completed 6/13/89
  4. * This is copyrighted by the author and not to be used in any commerical
  5. * application (excepting Amiga demonstrations) with out his permission.
  6. * However, it may be freely used any duplicated for any non-commercial
  7. * applications.
  8.  
  9.     INCLUDE    "exec/types.i"    ;Needed for SOFFSET macro
  10.     INCLUDE    "graphics/rastport.i"
  11.     INCLUDE    "intuition/intuition.i"
  12.  
  13.  
  14.     mc68881
  15.  
  16.     XDEF    _FuncFind
  17.     XDEF    _ConExt
  18.     
  19.     XREF    _LVOSetAPen
  20.     XREF    _LVOWritePixel
  21.  
  22.  
  23.     XREF    _GfxBase
  24.     XREF    _LVOSetAPen
  25.     XREF    _LVOWritePixel
  26.  
  27.  
  28.     XREF    _Factor
  29.     XREF    _XCenter
  30.     XREF    _YCenter
  31.  
  32.     XREF    _xtemp
  33.     XREF    _ytemp
  34.     XREF    _LacMod
  35.  
  36.     XREF    _IntWindow
  37.     XREF    _CWRast
  38.     XREF    _SWidth
  39.     XREF    _SHeight
  40.     XREF    _S1Width
  41.     XREF    _S1Height
  42.     XREF    _CurCnt
  43.     XREF    _MaxCnt
  44.     
  45.  
  46. PlotIt:
  47.     move.l    _CurCnt,d0        ;Get Mandelbrot count
  48.     cmp.l    #$FFFF,d0    ;See if indicated as M.B. It won't be this big
  49.     bne.s    MandOut
  50.     move.l    #15,d0
  51.     bra.s    SetC
  52. MandOut:
  53.     ext.l    d0
  54.     lsr.l    #2,d0
  55.     add.l    #1,d0
  56. SetC:
  57.     move.l    _CWRast,a1
  58.     move.b    d0,rp_FgPen(a1)
  59.     move.l    _ytemp,d1
  60.     cmp.l    #49,d1
  61.     bge.s    OKay        ;Use my SetPix if below Menus,
  62.     movem.l    d0-d7/a0-a6,-(a7)    ;Otherwise use WritePixel.
  63.     move.l    a1,-(a7)        ;Save raster port
  64.     move.l    _GfxBase,a6
  65.     jsr    _LVOSetAPen(a6)
  66.     move.l    _IntWindow,a0
  67.     move.w    wd_MouseY(a0),d0
  68.     cmp.w    #49,d0
  69.     blt.s    IntSet            ;Mouse in menu region
  70.     cmp.l    #10,_ytemp        ;See if y less than 12
  71.     ble.s    IntSet
  72.     bra.s    MySet
  73. IntSet:    move.l    _xtemp,d0
  74.     move.l    _ytemp,d1
  75.     move.l    (a7)+,a1
  76.     jsr    _LVOWritePixel(a6)
  77.     movem.l    (a7)+,d0-d7/a0-a6
  78.     rts
  79. MySet:    move.l    (a7)+,a1    ;Recover Raster port
  80.     movem.l    (a7)+,d0-d7/a0-a6
  81. OKay:    move.l    _xtemp,d0
  82.     bsr    SetOne
  83.     rts
  84.  
  85. SetOne:
  86.     cmp.w    _SWidth,d0
  87.     bge.s    SetNot
  88.     cmp.w    _SHeight,d1
  89.     bgt.s    SetNot
  90.     tst.l    d1        ;See if -
  91.     bmi.s    SetNot
  92.     bsr    SetPix
  93. SetNot:
  94.     rts
  95.  
  96. *SetPix has inputs of d0.w for x, d1.w for y, and a3 for the video pointer
  97. * Registers affected include d1, d2, and a0. It returns with the address
  98. * of the pixel in a0 and the bit to be set or cleared in d1
  99. SetPix:
  100.     movem.l    d0-d3/a0-a2,-(a7)
  101.     move.b    rp_FgPen(a1),d3        ;Get mask for rastport
  102.     move.l    rp_BitMap(a1),a1    ;Get pointer to bitmap
  103.     move.l    a1,a2        ;Save bit map pointer in a2
  104.     addq.l    #bm_Planes,a1    ;Get pointer to planes
  105.     move.w    d1,d2        ;See if y is - and get into d2
  106.     bmi.s    SetNo        ;Don't set if negative
  107.     cmp.w    (_S1Height+2),d1
  108.     bgt.s    SetNo
  109.     move.w    d1,d2        ;y is in d2
  110.     move.w    d0,d1        ;See if x is negative
  111.     bmi.s    SetNo        ;Don't set if is
  112.     cmp.w    (_S1Width+2),d0
  113.     bgt.s    SetNo        ;bcc.s    SetNo        ;If no carry then too big
  114.     move.l    d2,d1        ;Save y  in d1
  115.     mulu    _SWidth,d1    ;Get Screen width times y
  116.     add.l    d0,d1        ;Add in x coordinate
  117.     lsr.l    #3,d1        ;d1 is x/8
  118.     move.l    d1,d2
  119.     move.w    d0,d1        ;d1 is x
  120.     eori.w    #7,d1        ;Toggle lowest 3 bits.
  121.     andi.w    #7,d1        ;Get 7 - x(mod 8)
  122.     ext.l    d3
  123.     move.l    d3,d0        ;Move pen color into d0
  124.     move.b    bm_Depth(a2),d3    ;Get depth in d3
  125. SetPln:    move.l    (a1)+,a0    ;Get pointer to bit plane
  126.     adda.l    d2,a0        ;Add in offset    
  127.     btst    #0,d0        ;See if 1st color
  128.     beq.s    NoOne
  129.     bset    d1,(a0)        ;Set bit 7-x(mod8)
  130.     bra.s    PlnOne
  131. NoOne:    bclr    d1,(a0)
  132. PlnOne:    asr.l    #1,d0        ;Move next bit in color down.
  133.     sub.b    #1,d3        ;See if all planes done.
  134.     bne.s    SetPln
  135. SetNo:    movem.l    (a7)+,d0-d3/a0-a2
  136.     rts
  137.  
  138.  
  139. * Convert relevant double precision values from main to extended precision.
  140. _ConExt:
  141.     fmove.x    fp0,-(a7)
  142.     fmove.d    _Factor,fp0
  143.     fmove.x    fp0,Factor
  144.     move.l    #2,d0
  145.     fmove.l    d0,fp0
  146.     fmove.x    fp0,Two
  147.     fmove.x    Factor,fp0
  148.     fmul.x    Two,fp0
  149.     fmul.x    fp0,fp0
  150.     fmove.x    fp0,Limit
  151.     fmove.d    _XCenter,fp0
  152.     fmove.x    fp0,XCenter
  153.     fmove.d    _YCenter,fp0
  154.     fmove.x    fp0,YCenter
  155.     fmove.x    (a7)+,fp0
  156.     rts
  157.     nop
  158.     nop
  159.     nop
  160.     nop
  161.     nop
  162.     nop
  163.     nop
  164.     nop
  165.     lea    Limit,a0    
  166. _FuncFind:
  167.     bsr    FncFnd
  168.     move.l    d7,_CurCnt
  169.     bsr    PlotIt
  170.     rts
  171.  
  172. FncFnd:
  173.     fmove.x    Two,fp7
  174.     fmove.x    Factor,fp6
  175.     move.l    _xtemp,d0
  176.     move.l    _ytemp,d1
  177.     tst.w    _LacMod
  178.     bne.s    IsLace
  179.     lsl.l    #1,d1        ;If non-interlace, double y.
  180. IsLace:    fmove.l    d0,fp0
  181.     fmove.l    d1,fp1
  182.     fsub.x    XCenter,fp0
  183.     fsub.x    YCenter,fp1
  184.     bsr    Mand
  185.     rts
  186.  
  187. Mand:    move.l    #0,d7        ;Initialize counter
  188.     fmove.l    d7,fp2        ;Place 0 in Zr
  189.     fmove.x    fp2,fp3        ;Same for Zi
  190. ZConv:    bsr.s    ZFind        ;Get next value for Zr and Zi
  191.     cmp.l    _MaxCnt,d7    ;See if to be assumed within Mandelbrot set
  192.     bgt.s    LimCnt
  193.     bra.s    ZConv
  194. LimCnt:    move.l    #$FFFF,d7    ;Indicate it is part of Mandelbrot
  195. NotMand:
  196.     rts
  197.  
  198. ZFind:    fmove.x    fp2,fp4        ;Get current Zr into temporary
  199.     fmove.x    fp3,fp5        ;Do same for Zi
  200.     fmul.x    fp4,fp4        ;Find Zr^2
  201.     fmul.x    fp5,fp5        ;Find Zi^2
  202.     fmove.x    fp5,-(a7)    ;Save Zi^2 on stack
  203.     fadd.x    fp4,fp5        ;Find z-squared
  204.     fcmp.x    Limit,fp5    ;See if > 2^2 (i.e. is |Z|>2?)
  205.     fbgt    TooBig        ;If so extablish count to failure
  206.     fmove.x    (a7)+,fp5    ;Recover Zi^2
  207.     fsub.x    fp5,fp4        ;Find Zr^2 - Zi^2
  208.     fdiv.x    fp6,fp4        ;Divide by factor to get part of new Zr
  209.     fadd.x    fp0,fp4        ;Find New Zr
  210.     fmul.x    fp2,fp3        ;Find original Zi*Zr
  211.     fmul.x    fp7,fp3        ;Find 2*Zi*Ze
  212.     fdiv.x    fp6,fp3        ;Divide by Factor
  213.     fadd.x    fp1,fp3        ;Add in original Zi to get new Zi
  214.     fmove.x    fp4,fp2        ;and get new Zr into fp2
  215.     addq.l    #1,d7        ;Increment counter
  216.     rts
  217. TooBig:    fmove.x    (a7)+,fp5    ;Recover fp5 to balance stack
  218.     fmove.x    fp2,fp5        ;See if fp5 really needed
  219.     addq.l    #4,a7        ;Balance stack for return from ZFind
  220.     bra.s    NotMand        ;Back to Main
  221.  
  222.  
  223.     dseg
  224.  
  225. Limit:    ds.l    3
  226. Factor:    ds.l    3
  227. Two:    ds.l    3
  228. XCenter:
  229.     ds.l    3
  230. YCenter:
  231.     ds.l    3
  232.  
  233.     END
  234.